﻿<?php
class Backstage extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper("url");
		$this->load->database();
		$this->load->library('session');
		@session_start();
		$ok=$this->session->userdata('admin');
		if(!isset($ok)||$ok!='ok'){
			redirect("backlogin/index");
		}
	}
	function index(){
		$this->load->view("backstage/index.html");
	}
	function top(){
		$this->load->view("backstage/top.html");
	}
	function left(){
		$this->load->view("backstage/left.html");
	}
	function right(){
		$this->load->view("backstage/right.html");
	}
	
	
	//作品展示
	function show_production(){
			$this->load->library('pagination');
			$sql="select * from works";
			$res=$this->db->query($sql);
			$a=count($res->result());//统计一共有几条数据
			//每页显示5条数据
			$page_size=5;
			$config['base_url'] = site_url('backstage/show_production');
			$config['total_rows'] = $a;//一共几条数据
			$config['per_page'] = $page_size;//每页显示多少条
			$config['first_link'] =' << ';
			$config['last_link'] = ' >> ';
			$config['next_link'] =' > ';
			$config['prev_link'] = ' < ';
			$config['uri_segment'] = 3;//默认就是3，看url的情况而定
			$this->pagination->initialize($config);
			$offset=$this->uri->segment(3);
			if(!$offset){$offset=0;}
			$sql="select * from works order by id desc limit $offset,$page_size";
			$res=$this->db->query($sql);
			$data['works']=$res->result();	
			$data['links']=$this->pagination->create_links();
		$this->load->view("backstage/show_production",$data);
	}
	//删除作品
	function del_production(){
		$this->load->model("Backstage_model");
		$flag=$this->Backstage_model->del_pro();
		if($flag){
			redirect("Backstage/show_production");}
	}
		
	
	//添加作品界面
	function add_production(){
		$this->load->view("backstage/add_production");
	}
	//添加作品
	function add_pro(){
		$this->load->model("Backstage_model");
		$this->Backstage_model->add_prod();
	}
	//编辑作品
	function edit_production(){
		$this->load->model("Backstage_model");
		$data['works']=$this->Backstage_model->get_pro();
		$this->load->view("backstage/edit_production",$data);
	}
	function check_edit_pro(){
		$this->load->model("Backstage_model");
		$this->Backstage_model->check_edit_prod();
	}
	
	//工作团队
	function show_partner(){
		$this->load->library('pagination');
			$sql="select * from team";
			$res=$this->db->query($sql);
			$a=count($res->result());//统计一共有几条数据
			//每页显示5条数据
			$page_size=5;
			$config['base_url'] = site_url('backstage/show_partner');
			$config['total_rows'] = $a;//一共几条数据
			$config['per_page'] = $page_size;//每页显示多少条
			$config['first_link'] =' << ';
			$config['last_link'] = ' >> ';
			$config['next_link'] =' > ';
			$config['prev_link'] = ' < ';
			$config['uri_segment'] = 3;//默认就是3，看url的情况而定
			$this->pagination->initialize($config);
			$offset=$this->uri->segment(3);
			if(!$offset){$offset=0;}
			$sql="select * from team order by id desc limit $offset,$page_size";
			$res=$this->db->query($sql);
			$data['team']=$res->result();	
			$data['links']=$this->pagination->create_links();
		$this->load->view("backstage/show_partner",$data);
	}
	
	
	//添加人员界面
	function add_partner(){
		$this->load->view("backstage/add_partner");
	}
	//添加人员
	function check_add_partner(){
		$this->load->model("Backstage_model");
		$this->Backstage_model->add_team();
	}
	
	//删除成员
	function del_team(){
		$this->load->model("Backstage_model");
		$flag=$this->Backstage_model->del_part();
		if($flag){
			redirect("Backstage/show_partner");}
	}
	
	//编辑成员
	function edit_partner(){
		$this->load->model("Backstage_model");
		$data['team']=$this->Backstage_model->get_team();
		$this->load->view("backstage/edit_partner",$data);
	}
	 function check_edit_partner(){
		$this->load->model("Backstage_model");
		$this->Backstage_model->check_edit_team();
	} 
	
	//关于我们
	function about_us(){
		$this->load->model("Backstage_model");
		$data['team']=$this->Backstage_model->get_about();
		$this->load->view("backstage/about_us",$data);
	}
	function edit_about_us(){
		$this->load->model("Backstage_model");
		$flag=$this->Backstage_model->edit_about();
		if($flag){
			redirect("Backstage/about_us");
		}else{
			echo "修改失败";
		}
	}
	
	//报名信息
	function ck_compus(){
		$this->load->model("Backstage_model");
		$data['enroll']=$this->Backstage_model->show_enroll();
		$this->load->view('backstage/compus',$data);
	}
	function del_enroll(){
		$this->load->model("Backstage_model");
		$flag=$this->Backstage_model->del_enr();
		if($flag){
			redirect("Backstage/ck_compus");}
	}
	//报名的详细信息
	function show_enroll(){
		$this->load->model("Backstage_model");
		$data['enroll']=$this->Backstage_model->show_enroll_xinxi();
		$this->load->view('backstage/show_enroll',$data);
	}
	
	
	//联系我们
	function contact_us(){
		$this->load->model("Backstage_model");
		$data['contact']=$this->Backstage_model->get_contact();
		$this->load->view('backstage/contact',$data);
	}
	//添加联系我们
	function add_contact(){
		$title=$this->input->post("title");
		$content=$this->input->post("content");
		$data=array(
					'title'=>$title,
					'content'=>$content
					);
		$query=$this->db->insert("contact",$data);
		if($query){
			redirect("Backstage/contact_us");
		}else{
			echo "上传失败";
		}
		
	}
	//删除联系我们
	function del_contact(){
		$this->load->model("Backstage_model");
		$flag=$this->Backstage_model->del_con();
		if($flag){
			redirect("Backstage/contact_us");}
	}
	
	//修改密码
	function ck_admin(){
		$data['username']=$this->session->userdata('username');
		$this->load->view('backstage/update_admin',$data);
	}
	
	//确认修改密码
	 function update_admin(){
				$this->load->model("Backstage_model");
				$id=$this->session->userdata('id');
				$password=$this->input->post("password");
				$password=md5($password);
				$new_password1=$this->input->post("new_password1");
				$new_password=$this->input->post("new_password");
				$admin_message=$this->Backstage_model->get_password($id);	
				$data['username']=$admin_message['username'];
				$username=$this->input->post("username");
				if($password!=$admin_message['password']){
					$data['error']="旧密码错误";
					$this->session->set_userdata("username",$admin_message['username']);
					$this->session->set_userdata("id",$id);
					$this->load->view("backstage/update_admin",$data);
				}
				else if($new_password1!=$new_password){
					$data['error']="两次密码输入不一致";
					$this->session->set_userdata("username",$admin_message['username']);
					$this->session->set_userdata("id",$id);
					$this->load->view("backstage/update_admin",$data);
				}else {
					$flag=$this->Backstage_model->update_admin($username,$new_password,$id);
					if($flag){
						$data['succese']="修改成功"; 
						$this->session->set_userdata("username",$username);
						$this->session->set_userdata("id",$id);
						$this->load->view("backstage/update_admin",$data);
					}
				}
		}
			
	
	
	
	
	
	
	
	
	
	
	
	
	
}?>